package com.lmk;

import javax.xml.namespace.QName;
import java.util.Scanner;

public class Project {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);

        int choose;
        String[] dishes={"红烧带鱼","鱼香肉丝","时令菜蔬"};//菜品名字
        double[] prices={28.0,20.0,10.0};//菜品价格
        System.out.println(dishes.length);
        String[][] orders=new String[1024][];
        int[] Like={0,0,0};
        int c=0;
            int pcs=0;
            String add=null;
        double[] sumPrices= new double[4]; // 保存订单的总金额
        int time=0;



            String name=null;

       do {
           System.out.println("欢迎使用“吃货联盟订单系统”");
           System.out.println("****************************");
           System.out.println("1.我要订餐");
           System.out.println("2.查看订单");
           System.out.println("3.签收订单");
           System.out.println("4.删除订单");
           System.out.println("5.我要点赞");
           System.out.println("6.退出系统");
           System.out.println("****************************");
           System.out.print("请选择");
           choose = sc.nextInt();
           if (choose > 0 && choose < 6) {
               switch (choose) {
                   case 1:
                       System.out.println("******我要订餐******");
                       System.out.print("请输入订餐人姓名：");
                        name=sc.next();
                       System.out.println("序号\t菜品\t\t单价");
                       for (int i = 0; i < dishes.length; i++) {
                           System.out.println(i+1+"\t" + dishes[i]+"\t" + prices[i]);
                       }
                       //判断输入编号 如果为正确下一样 否则循环
                       int dishNum;
                       do {
                           System.out.println("请输入菜品编号");
                           dishNum = sc.nextInt();
                           if (dishNum < 1 || dishNum > dishes.length) {
                               System.out.println("输入错误请重新输入");

                           }
                       } while (dishNum < 1 || dishNum > dishes.length);

                       do {
                           System.out.print("请输入份数");
                           pcs = sc.nextInt();
                           if (pcs < 1) {
                               System.out.println("输入错误请重新输入");
                           }
                       } while (pcs < 1);

                       do {
                           System.out.println("请输入配送时间（10点至20点)");
                           time = sc.nextInt();
                           if (time < 10 || time > 20) {
                               System.out.println("输入错误请重新输入");
                           }
                       } while (time < 10 || time > 20);
                       System.out.println("请输入配送地址");
                         add = sc.next();
                       System.out.println("订单成功！");
                       System.out.println("您订的是" + dishes[dishNum - 1] + pcs + "份");
                       System.out.println("你选择的送餐时间" + time);
                       double all = prices[dishNum - 1] * pcs;
                       double cost = all > 50 ? 0 : 5;
                       System.out.println("餐费" + all + "元，" + "配送费" + cost + "元，" + "总计" + (cost + all) + "元，");
                       for (int i = 0; i < orders.length; i++) {
                           if(orders[i]==null){ //判断二位数组里原来有没有东西，如果为空，可以插入
                               orders[i]=new String[2]; //因为不知道二位数组的长度，所以用new
                               orders[i][0]=name+"\t"+dishes[dishNum-1]+" "+pcs+"份\t"+time+"点\t"+ "\t"+(cost+all)+"元";
                               orders[i][1]="已预订";
                               break;   //插完元素就跳出去，不可以重复插入到整个数组中
                           }
                       }

                       break;
                   case 2:
                       System.out.println("****查看订单****");
                       System.out.println("序号\t订餐人\t餐品信息\t送餐日期\t送餐地址\t总金额\t\t订单状态");
                       for (int i = 0; i <orders.length ; i++) {
                          if (orders[i]!=null) {
                               System.out.println(i + 1 + "\t" + orders[i][0] + "\t" + orders[i][1]);
                           }else {break;}

                       }
                       break;
                   case 3:
                       System.out.println("****查看订单****");
                       System.out.println("序号\t订餐人\t餐品信息\t送餐日期\t送餐地址\t总金额\t\t订单状态");
                       for (int i = 0; i <orders.length ; i++) {
                           if (orders[i]!=null) {
                               System.out.println(i + 1 + "\t" + orders[i][0] + "\t" + orders[i][1]);
                           }else {break;}


                       }
                       int num=0;
                       int end=0;
                       do {
                           System.out.println("请选择要签收的订单序号：");
                           for (int i = 0; i < orders.length; i++) {
                               if(orders[i]==null) {
                                   end=i;
                                   break;  //遍历已经输入的订单，遇到空就知道跳出
                               }
                           }
                           num=sc.nextInt();
                           if(num<1||num>end){
                               System.out.println("输入有误，请重新输入！");
                           }else if(!"已预订".equals(orders[num-1][1])){
                               System.out.println("订单已签收，不能重复签收");
                           }else{
                               orders[num-1][1]="已完成";
                               break;
                           }
                       }while(num<1||num>end||!"已完成".equals(orders[num-1][1]));
                       break;
                   case 4:
                       System.out.println("***删除订单***");
                       System.out.println("序号\t订餐人\t餐品信息\t送餐日期\t送餐地址\t总金额\t\t订单状态");
                       for (int i = 0; i < orders.length; i++) {
                           if (orders[i] != null) {
                               System.out.println(i + 1 + "\t" + orders[i][0] + "\t" + orders[i][1]);
                           } else {
                               break;

                           }

                       }
                       int n = 0;
                       int e = 0;
                       do {
                           System.out.println("请输入要输出的订单序号");
                           for (int i = 0; i < orders.length; i++) {
                               if (orders[i] == null) {
                                   e = i;
                                   break;
                               }
                           }
                           n = sc.nextInt();
                           boolean isDeleted = false;

                           if (n < 1 || n > e) {
                               System.out.println("对不起，你的输入有误，请重新输入");
                           } else if (!"已完成".equals(orders[n-1][1])) {
                               System.out.println("不能删除未完成的订单");
                           } else {
                               boolean isDelete = true;
                               for (int i = n - 1; i < orders[i].length; i++) {
                                   if (n - 1 == orders.length) {
                                       orders[i] = null;
                                       isDelete = true;
                                   } else {
                                       orders[i] = orders[i + 1];//前移
                                       if (orders[i] == null) {
                                           isDelete = true;
                                           break;
                                       }
                                   }
                               }
                               if (isDelete) {
                                   break;
                               }
                           }
                       } while (n < 1 || n > e || !"已预订".equals(orders[n-1][ 1]));
                       break;
                   case 5:
                       System.out.println("******我要点赞******");
                       System.out.println("序号\t菜品\t\t单价\t\t点赞数");
                       for (int i = 0; i < dishes.length; i++) {
                           System.out.println(i+1+"\t"+dishes[i]+"\t"+prices[i]+"\t\t"+Like[i]+"次点赞");
                       }
                       int d;
                       do{
                           System.out.print("请选择你要点赞的菜品：");
                           d=sc.nextInt();
                           if(d<1||d>Like.length){
                               System.out.println("对不起，你的输入有误，请重新输入！");
                           }else{
                               Like[d-1]++;
                           }
                       }while(d<1||d>Like.length);
                       break;
                   default:
               }
               System.out.print("输入0返回主页：");
               choose=sc.nextInt();
           }else {
               break;
           }
       }while(choose==6);
        System.out.println("谢谢使用，欢迎下次光临！");
    }
}

